var error_msg_158 = ""; function validate_email_158(mail) { if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(mail)) { return (true); } error_msg_158 = "Имэйл хаягаа зөв оруулна уу"; return (false); } function getCookie_158(cname) { var name_158 = cname + "="; var decodedCookie_158 = decodeURIComponent(document.cookie); var ca_158 = decodedCookie_158.split(';'); for(var i = 0; i < ca_158.length; i++) { var c_158 = ca_158[i]; while (c_158.charAt(0) == ' ') { c_158 = c_158.substring(1); } if (c_158.indexOf(name_158) == 0) { return c_158.substring(name_158.length, c_158.length); } } return ""; } function subscribe_submit_158(){ var form_158 = document.querySelector('#subscribe-form-158'); var data_158 = new FormData(form_158); var url_158 = "/api.php/subscription/save?site_id=324&id=158" + '&cookie_id=' + getCookie_158("cookie_id") + '&short_cookie_id=' + getCookie_158("short_cookie_id"); var xhr_158 = new XMLHttpRequest(); if (window.XMLHttpRequest) { // Mozilla, Safari, ... var xhr_158 = new XMLHttpRequest(); } else if (window.ActiveXObject) { // IE var xhr_158 = new ActiveXObject("Microsoft.XMLHTTP"); } xhr_158.open('POST', url_158, true); xhr_158.onload = function () { /* do something to response */ console.log(this.responseText); document.getElementById("subscription-form-container-158").innerHTML = this.responseText; }; var valid_158 = 1; if(form_158.querySelector('input[name="subscriber[name]"]')){ if(form_158.querySelector('input[name="subscriber[name]"]').value.trim().length > 0){ }else{ valid_158 = 0; form_158.querySelector('input[name="subscriber[name]"]').setAttribute("style", "border-color: red;"); } } if(form_158.querySelector('input[name="subscriber[email]"]')){ if(form_158.querySelector('input[name="subscriber[email]"]').value.trim().length > 0){ }else{ valid_158 = 0; form_158.querySelector('input[name="subscriber[email]"]').setAttribute("style", "border-color: red;"); } } if(form_158.querySelector('input[name="subscriber[phone]"]')){ if(form_158.querySelector('input[name="subscriber[phone]"]').value.trim().length > 0){ }else{ valid_158 = 0; form_158.querySelector('input[name="subscriber[phone]"]').setAttribute("style", "border-color: red;"); } } if(form_158.querySelector('input[name="subscription[company_name]"]')){ if(form_158.querySelector('input[name="subscription[company_name]"]').value.trim().length > 0){ }else{ valid_158 = 0; form_158.querySelector('input[name="subscription[company_name]"]').setAttribute("style", "border-color: red;"); } } if(form_158.querySelector('input[name="subscription[company_position]"]')){ if(form_158.querySelector('input[name="subscription[company_position]"]').value.trim().length > 0){ }else{ valid_158 = 0; form_158.querySelector('input[name="subscription[company_position]"]').setAttribute("style", "border-color: red;"); } } if(form_158.querySelector('input[name="subscription[title]"]')){ if(form_158.querySelector('input[name="subscription[title]"]').value.trim().length > 0){ }else{ valid_158 = 0; form_158.querySelector('input[name="subscription[title]"]').setAttribute("style", "border-color: red;"); } } if(form_158.querySelector('textarea[name="subscription[body]"]')){ if(form_158.querySelector('textarea[name="subscription[body]"]').value.trim().length > 0){ }else{ valid_158 = 0; form_158.querySelector('textarea[name="subscription[body]"]').setAttribute("style", "border-color: red;"); } } if(valid_158 == 0){ error_msg_158 = "Талбаруудыг бүрэн бөглөнө үү!"; } if(!validate_email_158(form_158.querySelector('input[name="subscriber[email]"]').value)){ form_158.querySelector('input[name="subscriber[email]"]').style="border-color: red;"; valid_158 = 0; }else{ } if(valid_158){ document.querySelector('#subscribe-form-158').style.display = "none"; document.querySelector('#subscription-form-loading-158').style.display = "inline"; xhr_158.send(data_158); }else{ alert(error_msg_158); } } // function postRequest_158(strURL) { var xmlHttp_158; if (window.XMLHttpRequest) { // Mozilla, Safari, ... var xmlHttp_158 = new XMLHttpRequest(); } else if (window.ActiveXObject) { // IE var xmlHttp_158 = new ActiveXObject("Microsoft.XMLHTTP"); } xmlHttp_158.open('POST', strURL, true); xmlHttp_158.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); xmlHttp_158.onreadystatechange = function() { if (xmlHttp_158.readyState == 4) { updatepage_158(xmlHttp_158.responseText); } } xmlHttp_158.send(strURL); } // function updatepage_158(str){ document.getElementById("subscription-form-container-158").innerHTML = str; } //'//asayake.mn' + var get_url_158 = '/api.php/subscription/renderform?site_id=324' + '&id=158' + '&placeholder[subscriber][name]=Овог нэр&placeholder[subscriber][email]=Имэйл&placeholder[subscriber][phone]=Утас&placeholder[subscription][title]=Хаяг&placeholder[subscription][body]=Барааны нэр,авах тоо ширхэг&label[subscriber][name]=Захиалагчийн овог нэр&label[subscriber][email]=Захиалгын мэдээлэл хүлээн авах имэйл&label[subscriber][phone]=Холбогдох утас&label[subscription][title]=Бараа хүлээн авах хаяг&label[subscription][body]=Захиалах барааны мэдээлэл&send=ЗАХИАЛГА ИЛГЭЭХ' ; postRequest_158(get_url_158);